package com.tonann.app.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.tonann.app.dto.AppDeviceDocumentDto;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tonann.common.annotation.Log;
import com.tonann.common.core.controller.BaseController;
import com.tonann.common.core.domain.AjaxResult;
import com.tonann.common.enums.BusinessType;
import com.tonann.app.domain.AppDeviceDocument;
import com.tonann.app.service.IAppDeviceDocumentService;
import com.tonann.common.utils.poi.ExcelUtil;
import com.tonann.common.core.page.TableDataInfo;

/**
 * 设备文档管理Controller
 * 
 * @author tonann
 * @date 2023-07-28
 */
@RestController
@RequestMapping("/app/deviceDocument")
public class AppDeviceDocumentController extends BaseController
{
    @Autowired
    private IAppDeviceDocumentService appDeviceDocumentService;

    /**
     * 查询设备文档管理列表
     */
    @PreAuthorize("@ss.hasPermi('app:deviceDocument:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppDeviceDocument appDeviceDocument)
    {
        startPage();
        List<AppDeviceDocument> list = appDeviceDocumentService.selectAppDeviceDocumentList(appDeviceDocument);
        return getDataTable(list);
    }

    /**
     * 导出设备文档管理列表
     */
    @PreAuthorize("@ss.hasPermi('app:deviceDocument:export')")
    @Log(title = "设备文档管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppDeviceDocument appDeviceDocument)
    {
        List<AppDeviceDocument> list = appDeviceDocumentService.selectAppDeviceDocumentList(appDeviceDocument);
        ExcelUtil<AppDeviceDocument> util = new ExcelUtil<AppDeviceDocument>(AppDeviceDocument.class);
        util.exportExcel(response, list, "设备文档管理数据");
    }

    /**
     * 获取设备文档管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('app:deviceDocument:query')")
    @GetMapping(value = "/{documentId}")
    public AjaxResult getInfo(@PathVariable("documentId") Long documentId)
    {
        return AjaxResult.success(appDeviceDocumentService.selectAppDeviceDocumentByDocumentId(documentId));
    }

    /**
     * 新增设备文档管理
     */
    @PreAuthorize("@ss.hasPermi('app:deviceDocument:add')")
    @Log(title = "设备文档管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppDeviceDocumentDto appDeviceDocument)
    {
        return toAjax(appDeviceDocumentService.insertAppDeviceDocument(appDeviceDocument));
    }

    /**
     * 修改设备文档管理
     */
    @PreAuthorize("@ss.hasPermi('app:deviceDocument:edit')")
    @Log(title = "设备文档管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppDeviceDocument appDeviceDocument)
    {
        return toAjax(appDeviceDocumentService.updateAppDeviceDocument(appDeviceDocument));
    }

    /**
     * 删除设备文档管理
     */
    @PreAuthorize("@ss.hasPermi('app:deviceDocument:remove')")
    @Log(title = "设备文档管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{documentIds}")
    public AjaxResult remove(@PathVariable Long[] documentIds)
    {
        return toAjax(appDeviceDocumentService.deleteAppDeviceDocumentByDocumentIds(documentIds));
    }
}
